{
  "contentVersion": "1.0.0.0",
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "parameters": {
    "webJobSiteName": {
      "type": "string",
      "metadata": {
        "description": "The name of the App Service Plan that will host the Web App."
      }
    },
    "webJobName": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The name of the web job."
      }
    },
    "hostingPlanName": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The name of the hosting Plan."
      }
    },
    "packageUrl": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The azure location of the web job binaries."
      }
    },
    "argumentUrl": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The url containing the key vault info."
      }
    },
    "frequencyjob": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The frequecny of the web job run."
      }
    },
    "intervaljob": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The interval between two web job runs."
      }
    },
    "start": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The start time of the web job run."
      }
    },
    "jobcollectionname": {
      "type": "string",
      "defaultValue": "",
      "metadata": {
        "description": "The job collection name for the web job schedule."
      }
    }
  },
  "variables": {
    "namePrefix": "[resourceGroup().name]",
    "uniqueNamePrefix": "[concat(variables('namePrefix'), uniqueString(subscription().subscriptionId))]",
    "location": "[resourceGroup().location]",
    "sfVersion": "2016-03-01",
    "wsVersion": "2016-03-01",
    "appspsku": "Standard",
    "workerSize": "1",
    "sfResourceId": "[resourceId('Microsoft.Web/serverFarms', parameters('hostingPlanName'))]",
    "jobfrequency": "[parameters('frequencyjob')]",
    "jobinterval": "[int(parameters('intervaljob'))]"
  },
  "resources": [
    {
      "apiVersion": "[variables('sfVersion')]",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverFarms",
      "location": "[variables('location')]",
      "properties": {
        "name": "[parameters('hostingPlanName')]",
        "workerSize": "[variables('workerSize')]",
        "numberOfWorkers": 1
      },
      "sku": {
        "name": "S1",
        "tier": "[variables('appspsku')]",
        "size": "S1",
        "family": "S",
        "capacity": "1"
      }
    },
    {
      "apiVersion": "[variables('wsVersion')]",
      "name": "[parameters('webJobSiteName')]",
      "type": "Microsoft.Web/Sites",
      "location": "[variables('location')]",
      "dependsOn": [
        "[variables('sfResourceId')]"
      ],
      "tags": {
        "[concat('hidden-related:', variables('sfResourceId'))]": "empty"
      },
      "properties": {
        "name": "[parameters('webJobSiteName')]",
        "serverFarmId": "[parameters('hostingPlanName')]",
        "siteConfig": {
        }
      },
      "resources": [
        {
          "apiVersion": "[variables('wsVersion')]",
          "name": "MSDeploy",
          "type": "extensions",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', parameters('webJobSiteName'))]"
          ],
          "tags": {
            "displayName": "[parameters('webJobName')]"
          },
          "properties": {
            "packageUri": "[parameters('packageUrl')]"
          }
        }
      ]
    },
    {
      "apiVersion": "[variables('wsVersion')]",
      "name": "[parameters('jobCollectionName')]",
      "type": "Microsoft.Scheduler/jobCollections",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites', parameters('webJobSiteName'))]"
      ],
      "location": "[variables('location')]",
      "properties": {
        "sku": {
          "name": "standard"
        },
        "quota": {
          "maxJobCount": "10",
          "maxRecurrence": {
            "Frequency": "[parameters('frequencyjob')]",
            "interval": "[parameters('intervaljob')]"
          }
        }
      },
      "resources": [
        {
          "apiVersion": "[variables('wsVersion')]",
          "name": "WebJobSchedule",
          "type": "jobs",
          "dependsOn": [
            "[resourceId('Microsoft.Scheduler/jobCollections', parameters('jobCollectionName'))]"
          ],
          "properties": {
            "startTime": "[parameters('start')]",
            "action": {
              "request": {
                "uri": "[concat(list(resourceId('Microsoft.Web/sites/config', parameters('webJobSiteName'), 'publishingcredentials'), variables('wsVersion')).properties.scmUri, concat('/api/triggeredwebjobs/', parameters('webJobName'), '/run?arguments=',parameters('argumentUrl')))]",
                "method": "POST"
              },
              "type": "http",
              "retryPolicy": {
                "retryType": "Fixed",
                "retryInterval": "PT1M",
                "retryCount": 2
              }
            },
            "state": "enabled",
            "recurrence": {
              "frequency": "[parameters('frequencyjob')]",
              "interval": "[int(parameters('intervaljob'))]"
            }
          }
        }
      ]
    }

  ]

}
